<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class MY_Encrypt extends CI_Encrypt
{
    
    /**
     * Constructor Method
     * @param type $config
     */
    function MY_Encrypt()
    {
        parent::__construct();
    }
    
    /**
     * Create url friendly encrypted string
     * @param string $string to be hashed
     * @param string $key encryption key
     * @param boolean $url_safe URL encode as default
     * @return string
     */
    function url_encode($string, $key = '', $url_safe = TRUE)
    {
        $ret = parent::encode($string, $key);
        if ($url_safe)
        {
            $ret = urlencode( str_replace(array('+','/','='), array('-','_','.'), $ret) );
        }
        return $ret;
    }

    /**
     * Decrypt url encoded encrypted string
     * @param sting $string url encoded encrypted string
     * @param string $key decription key
     * @return type
     */
    function url_decode($string, $key = '')
    {
        $str = str_replace(array('-','_','.'), array('+','/','='), urldecode($string));
        return parent::decode($str, $key);
    }
}